package com.qiao.dfw.loggic.hall;

import com.qiao.dfw.loggic.ATask;
import com.qiao.dfw.loggic.ECode;
import com.qiao.dfw.loggic.HallTask;
import com.qiao.dfw.manager.RoomStatus;
import com.qiao.dfw.network.Connection;
import com.qiao.dfw.network.ConnectionManager;
import com.qiao.dfw.proto.Hall;
import com.qiao.dfw.proto.Login;
import com.qiao.dfw.proto.Role;
import com.qiao.dfw.thread.EThreadType;
import com.qiao.dfw.thread.ThreadManager;
import com.qiao.dfw.thread.ThreadTask;
import com.qiao.dfw.thread.Threads;

/**
 * @author 乔占江 qq:59663479
 * @version 1.0
 * @date 2024/1/18 5:32
 * @description
 */
public class LookTask extends HallTask<Hall.LookRequest> {
    @Override
    public void execute0() {
        Connection netConn = ConnectionManager.getNetConn(request.getUid());
        if (netConn != null
                && netConn.player != null
                && netConn.player.room != null
                && netConn.player.room.roomStatus == RoomStatus.Battle) {
            conn.player.room = netConn.player.room;
            Threads thread = ThreadManager.getThreads(EThreadType.Battle, conn.player.room.threadId);
            thread.push(new ThreadTask() {
                @Override
                public void execute() {
                    Hall.LookResponse.Builder build = Hall.LookResponse.newBuilder();
                    Role.MapData data = conn.player.room.getBattleData(player);
                    build.setData(data);
                    sendMsg(build.build().toByteArray());
                    conn.player.room.lookBattle(conn.player);
                }
            });

        }
    }

    @Override
    public ECode getCode() {
        return ECode.Look;
    }
}
